package com.jiyejia.activity;

import com.jiyejia.R;

import android.os.Bundle;
import android.app.TabActivity;
import android.content.Intent;
import android.view.Window;
import android.widget.RadioGroup;
import android.widget.TabHost;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.TabHost.TabSpec;
/**
 *
 * @author Jj
 *
 */
public class MainActivity extends TabActivity implements OnCheckedChangeListener {
	private RadioGroup mRadioGroup;
	private TabHost mTabHost;
	public static final String TAB_ITEM_1 = "tabItem1";
	public static final String TAB_ITEM_2 = "tabItem2";
	public static final String TAB_ITEM_3 = "tabItem3";
	public static final String TAB_ITEM_4 = "tabItem4";
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_main);
        mRadioGroup = (RadioGroup)findViewById(R.id.main_radio);
        mRadioGroup.setOnCheckedChangeListener(this);
        mTabHost = this.getTabHost();
        TabSpec tab1 = mTabHost.newTabSpec(TAB_ITEM_1);
		TabSpec tab2 = mTabHost.newTabSpec(TAB_ITEM_2);
		TabSpec tab3 = mTabHost.newTabSpec(TAB_ITEM_3);
		TabSpec tab4 = mTabHost.newTabSpec(TAB_ITEM_4);
		
		tab1.setIndicator(TAB_ITEM_1).setContent(new Intent(this, OrderActivity.class));
		tab2.setIndicator(TAB_ITEM_2).setContent(new Intent(this, SearchActivity.class));
		tab3.setIndicator(TAB_ITEM_3).setContent(new Intent(this, HistoryActivity.class));
		tab4.setIndicator(TAB_ITEM_4).setContent(new Intent(this, AboutActivity.class));
		
		mTabHost.addTab(tab1);
		mTabHost.addTab(tab2);
		mTabHost.addTab(tab3);
		mTabHost.addTab(tab4);
		mTabHost.setCurrentTabByTag(TAB_ITEM_1);
    }

	@Override
	public void onCheckedChanged(RadioGroup group, int checkedId) {
		switch (checkedId) 
		{
		case R.id.radio_button1:
			mTabHost.setCurrentTabByTag(TAB_ITEM_1);
			break;
		case R.id.radio_button2:
			mTabHost.setCurrentTabByTag(TAB_ITEM_2);
			break;
		case R.id.radio_button3:
			mTabHost.setCurrentTabByTag(TAB_ITEM_3);
			break;
		case R.id.radio_button4:
			mTabHost.setCurrentTabByTag(TAB_ITEM_4);
			break;
		default:
			break;
		}
		
	}

}
